package com.zch.threaduse;

public class ThreadMethod02 {
    public static void main(String[] args) throws InterruptedException {
        T2 t2 = new T2();
        t2.start();

        for (int i = 1 ; i <= 10 ; i++){
            Thread.sleep(1000);
            System.out.println("主线程(小弟) 吃了 " + i + " 包子");
            if (i == 5){
                System.out.println("主线程(小弟) 让 子线程(老大) 先吃");
                //join 线程插队
                t2.join(); //相当于 让t2 线程先执行完毕
                //Thread.yield(); //主线程 礼让， 不一定成功
                System.out.println("线程(老大) 吃完了 主线程(小弟) 接着吃 ...");
            }
        }
    }
}

class T2 extends Thread{
    @Override
    public void run() {
        for (int i = 1; i <= 15; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("子线程(老大) 吃了" + i + " 包子");
        }
    }
}
